# Maintainer: David Runge <dvzrv@archlinux.org>

_name=falcon
pkgname=python-falcon
pkgver=3.1.1
pkgrel=4
pkgdesc="Web API framework for fast and reliable microservices, proxies, and app backends"
arch=(loong64 x86_64)
url="https://falconframework.org/"
license=(Apache)
depends=(
  glibc
  python
)
makedepends=(
  cython
  python-build
  python-installer
  python-setuptools
  python-wheel
)
# TODO: add python-daphne
checkdepends=(
  gunicorn
  hypercorn
  python-aiofiles
  python-cbor2
  python-httpx
  python-jsonschema
  python-mimeparse
  python-msgpack
  python-mujson
  python-orjson
  python-pecan
  python-pytest
  python-pytest-asyncio
  python-pytest-runner
  python-pyyaml
  python-rapidjson
  python-requests
  python-testtools
  python-ujson
  python-websockets
  uvicorn
)
optdepends=(
  'python-bottle: for falcon-bench'
  'python-django: for falcon-bench'
  'python-flask: for falcon-bench'
  'python-jsonschema: for JSON schema validation'
  'python-msgpack: for MessagePackHandler'
  'python-pecan: for falcon-bench'
  'python-pprofile: for falcon-bench'
)
# not all required files for tests contained in pypi sdist tarball: https://github.com/falconry/falcon/issues/2051
# source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
source=($_name-$pkgver.tar.gz::https://github.com/falconry/$_name/archive/refs/tags/$pkgver.tar.gz)
sha512sums=('d6d0ff20a64400a28e45bf30de38c1d989f78f0aef97467a1e464aa3bffca8027728948fae604f2fecd00cc79488301b2d842c0c1436ee15f50c666e03ff9ecd')
b2sums=('7c9d1bab73df864632f6d649a4a9894b35837bcca91eb05ce67447b4139274cd326e31f88ed3a0015a3dd82509b5d8d7ab1f439d0fdd190957e06b49f51daa9b')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv tests/
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
